<template>
  <div class="comment-replay">
    <!-- 1.头部nav-bar  -->
    <van-nav-bar
    fixed
    :title="comment.reply_count?
    comment.reply_count+'条回复' : '当前没有评论'" >
        <van-icon
        slot="left"
        name="cross"
        color="black"
        @click="$emit('onisreplyShow')"/>
    </van-nav-bar>
    <div  class="scroll-wrap">
         <!-- 2.当前评论 -->
    <CommentItem :comment_item ='comment'></CommentItem>
    <!-- 全部恢复 -->
    <van-cell title=" 全部回复"></van-cell>
    <!-- //传递type未false表示请求的时回复列表 -->
    <CommentList ref="commentList" v-if="isreplyShow" :type='false' :source='comment.com_id'></CommentList>
    </div>

    <!-- 写评论 -->
    <div class="post-wrap">
        <van-button
         round
         size="small"
         class="post-btn"
         @click="isPostShow= true"
         >写评论</van-button>
    </div>
    <!-- 写评论 -->

    <van-popup v-model="isPostShow" position="bottom">
        <!-- //评论弹层组件 -->
        <commentPost
            :target ='comment.com_id'
            @post-success='onPonstSuccess'>
        </commentPost>
        <!-- //评论弹层组件 -->
    </van-popup>
  </div>
</template>

<script>
import commentPost from './comment-post.vue'
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
export default {
  props: {
    comment: {
      type: Object,
      require: true
    },
    isreplyShow: {
      type: Boolean,
      requried: true
    }

  },
  data () {
    return {
      isPostShow: false
    }
  },
  name: 'comment-replay',
  components: {
    CommentItem,
    CommentList,
    commentPost
  },
  methods: {
    onPonstSuccess (data) {
    // 1.关闭弹窗
      this.isPostShow = false
      // 2.将发布的评论添加进数组
      // console.log(data)

      this.$refs.commentList.list.unshift(data)
      // 3.总评论数++
      // eslint-disable-next-line vue/no-mutating-props
      this.comment.reply_count++
    }
  }
}
</script>

<style scoped lang="less">
    .scroll-wrap {
    position: fixed;
    top: 92px;
    left: 0;
    right: 0;
    bottom: 88px;
    overflow-y: auto;
}
.post-wrap {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: #fff;
    border-top: 1px solid #d8d8d8;
    .post-btn {
     width: 60%;
    }
}
</style>
